package lock;

import java.util.concurrent.TimeUnit;

public class Demo1 {

    public static void main(String[] args) {
        Computer computer = new Computer();

        new Thread(()->{
            computer.listenMusic();
        },"A").start();

        try {
            //线程休息1毫秒
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(()->{
            computer.program();
        },"B").start();


    }
}

class Computer{

    public synchronized void listenMusic(){
        try {
            //线程休息1毫秒
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("听音乐！");
    }

    public synchronized void program(){
        System.out.println("编程！");
    }
}